package CtrLayer;
import ModelLayer.*;

public class StaffCtr
{
    private static StaffList instance = StaffList.getInstance();
    
    public StaffCtr()
    {
        instance.addStaff(new Manager(1,"Mircea","Sofiendalsvej 60","9000","457812","some123@ucn.dk","1","1"));
        instance.addStaff(new Employee(2,"Ivan","Sofiendalsvej 90","9000","457812","some123@ucn.dk","2","2"));
    }
    
    
    public int login(String username, String password)
    {
        try
        {
            Staff staff = instance.getStaffMember(username);
            if(staff.getPassword().equals(password)) 
            {
                if(staff instanceof Manager) return 2;
                return 1;
            }
        }
        catch(Exception e) {}
        
        return 0;
    }
    
    public void createEmployee(int i, String n, String a, String pc, String ph, String e, String u, String ps)
    {
        Employee emp = new Employee(i, n, a, pc, ph, e, u, ps);
        instance.addStaff(emp);
    }
    
    public void createManager(int i, String n, String a, String pc, String ph, String e, String u, String ps)
    {
        Manager man = new Manager(i, n, a, pc, ph, e, u, ps);
        instance.addStaff(man);
    }
    
    public Staff getStaff(String username)
    {
        return instance.getStaffMember(username);
    }
    
    public Staff getStaffById(int id)
    {
        return instance.getStaffMember(id);
    }
    
    public boolean deleteStaff(int id)
    {
        return instance.deleteStaffMember(id);
    }
    
    public boolean updateStaff(int id, String updateValue, int opt)
    {
        Staff s = getStaffById(id);
        try{
            switch(opt)
            {
                case 1 : { s.setName(updateValue); } break;
                case 2 : { s.setAddress(updateValue); } break;
                case 3 : { s.setPostCode(updateValue); } break;
                case 4 : { s.setPhone(updateValue); } break;
                case 5 : { s.setEmail(updateValue); } break;
                case 6 : { s.setUsername(updateValue); } break;
                case 7 : { s.setPassword(updateValue); } break;
            }
            return true;
        }
        catch(Exception e){}
        return false;
    }
}
